﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Dss.Methods;
using Dss.Data;

namespace CECB
{
    /// <summary>
    /// Interaction logic for ProjectActivities_Window.xaml
    /// </summary>
    public partial class ProjectActivities_Window : Window
    {
        Dss.Methods.ProjectActivities pro;

        public ProjectActivities_Window()
        {
            InitializeComponent();
            pro = new Dss.Methods.ProjectActivities();
            label_ProjectCat.Content = "____________________________________";
            label_ProjectReference.Content = "____________________________________";
        }

        private void comboBox_ProjectName_DropDownOpened(object sender, EventArgs e)
        {
            comboBox_ProjectName.ItemsSource = pro.getAllProjectNames();
        }

        private void comboBox_ProjectName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            label_ProjectReference.Content = comboBox_ProjectName.SelectedValue.ToString();
            label_ProjectCat.Content = pro.getAllProjectCatByReference(comboBox_ProjectName.SelectedValue.ToString());
        }
        //Button Close
        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        //Button Save
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {

            if(textBox_ProjectAct.Text.Length==0)
            {
                MessageBox.Show("Enter Project Activity");
            }
            else if (comboBox_ProjectPhase.SelectedIndex == -1)
            {
                MessageBox.Show("Select Project Phase");
            }
            else
            {
                String activityName = textBox_ProjectAct.Text.Trim();
                String phase = comboBox_ProjectPhase.Text.ToString();



                Dss.Methods.ProjectActivities pactivity = new ProjectActivities();
               bool isIsnsert =   pactivity.InsertProjectActivity(activityName,phase);

               if (isIsnsert) 
               {
                   MessageBox.Show("Activity Inserted Successfully");
                   clear();
               }
            }
        }

        public void clear() 
        {
            textBox_ProjectAct.Clear();
            comboBox_ProjectName.SelectedIndex = -1;
            comboBox_ProjectPhase.SelectedIndex = -1;
            label_ProjectCat.Content = "";
            label_ProjectReference.Content = "";
        }
    }
}
